package com.base.dao;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.base.bean.*;

/**
 * 
 * @author Administrator
 *
 */
public class MsessionObjDao extends _BaseDao<MsessionObj>{
	
	public int changeState(int msessionId,int state){
		Session session =null;
		Transaction tx = null;
		
	try{session = this.getSessionFactory().getCurrentSession();
		tx =session.beginTransaction();	
		
		String hqlUpdate = "update MsessionObj a set a.state = :state where a.msid= :id ";
		// or String hqlUpdate = "update Customer set name = :newName where name = :oldName";
		int updatedEntities = session.createQuery( hqlUpdate )
		        .setInteger( "state",state)
		        .setInteger( "id",msessionId)	        
		.executeUpdate();
		tx.commit();
		return updatedEntities;
	}catch(Exception e){
		e.printStackTrace();
		session.beginTransaction().rollback();
		return 0;
	}finally{
		if(session.isOpen())
			session.close();
	}
	}

}
